import axios from 'axios';
import base from '@/common/services/base';
const apiUrl = base.test;
import {setCookie} from '@/utils/cookiesUtil.js'

export default function getOauth() {
  setCookie('token', '');
  const url = window.location.href;
  axios({
    url: `${apiUrl}/wechat/getWeChatRedirectUri`,
    method: 'post',
	//设置请求头
	headers: {
		'Content-Type': 'application/x-www-form-urlencoded'
	},
    data: {
      destination: `${url.split('code=')[0].split('state=')[0]}`
    },
	transformRequest: [function (data) {
      let ret = ''
      for (let it in data) {
        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
      }
      return ret
    }],
  }).then(res => {
    if (res.data && res.data.code === 0) {
      location.href = res.data.result.redirectUri;
    }
  });
}